﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RoyTools.D3Monitor.FormUI.Helper
{
    /// <summary>
    /// 数据辅助类
    /// </summary>
    public class DataHelper
    {
        /// <summary>
        /// 实体转ListViewItem
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public static ListViewItem EntityToListViewItem<T>(string headValue, T t) where T : class
        {
            var listViewValues = new List<string>() { headValue };
            var properties = t.GetType().GetProperties().ToList();
            properties.ForEach(p =>
            {
                listViewValues.Add(p.GetValue(t, null).ToString());
            });
            return new ListViewItem(listViewValues.ToArray());
        }
    }
}
